package com.fuyu.system.utils;


import com.alibaba.fastjson2.JSON;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

public class ResponseUtils {
    public static void send(HttpServletResponse response, Map<String, Object> res) throws IOException, IOException {
        //设置编码格式为UTF-8
        response.setCharacterEncoding("UTF-8");
        //通过设置响应头控制浏览器以UTF-8的编码显示数据，如果不加这句话，那么浏览器显示的将是乱码
        response.setHeader("content-type", "text/json;charset=UTF-8");

        //使用PrintWriter流向客户端输出字符
        PrintWriter out = response.getWriter();

        //json字符串
        String data = JSON.toJSONString(res);

        //响应
        out.write(data);

    }
}
